{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e7dac88c-21b0-4de3-b256-e6e4e1b74505",
   "metadata": {},
   "source": [
    "# 参考"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2cd218ca-78ab-4acb-8987-2a5f8b2e664f",
   "metadata": {},
   "source": [
    "Python菜鸟教程：https://www.runoob.com/python3/python3-tutorial.html\n",
    "\n",
    "Markdown标题介绍：T2-P7 ： https://www.bilibili.com/video/BV1a3411H7kP?p=7\n",
    "\n",
    "2021年统计公报：http://www.gov.cn/xinwen/2022-02/28/content_5676015.htm\n",
    "\n",
    "2020年统计公报：http://www.gov.cn/xinwen/2021-02/28/content_5589283.htm"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7786086-8986-424a-8db0-40f11a2913f8",
   "metadata": {},
   "source": [
    "## jupyter快捷键"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ca57600-b86c-4f8c-b329-9bf712cef7ce",
   "metadata": {},
   "source": [
    "### 分割shift ctrl  -  合并 shift M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "fc207dd7-c684-4dd5-b45b-4f1efaee5057",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "\n",
    "a = 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b70d5cb6-c463-4fbc-ba38-00ae41908310",
   "metadata": {},
   "source": [
    "### tab提示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "4b49843f-b840-490b-88b9-e4e5089447c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate = 0.1\n",
    "gdp_text = 'GDP增速'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "c3209cdc-a865-4b1e-b41c-0e024431f6bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速'"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cdebee5c-d807-4986-96b3-607688f03a97",
   "metadata": {},
   "source": [
    "### shift tab弹出注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ef784e9-694c-47b1-9093-2c47a2c2f739",
   "metadata": {},
   "outputs": [],
   "source": [
    "type()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15f35658-a8a3-4872-b126-45fc0ad7c1b8",
   "metadata": {
    "tags": []
   },
   "source": [
    "# 经济数据计算"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7ed0eed-0379-48b5-8841-2d1ff3ff72d4",
   "metadata": {},
   "source": [
    "## 数值型"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e907831d-ab4e-4e1d-9969-48bb524faf2c",
   "metadata": {
    "tags": []
   },
   "source": [
    "### 数值型介绍"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fcbbcf7b-9ce6-481c-914a-aacdf475911b",
   "metadata": {},
   "source": [
    "整数型 integer int "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1ad6570d-1917-44a8-b505-4161e0970be9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "784fde16-12d4-4ead-9af8-bfbb0d250957",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78d53a32-518e-4775-879d-b00df179b933",
   "metadata": {},
   "source": [
    "浮点型 float"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f6060789-451c-4c8d-a20b-2d8441f52bad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8e6fe729-29b3-40c8-925c-b8501f9dde0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8107a327-5f80-49ad-a73a-c5b4cfe345cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "439de728-b383-4f9c-aac5-920ff8b22252",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ".1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c224cc21-ca4f-4818-a844-b46e3f3a5511",
   "metadata": {},
   "source": [
    "复数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "79f8b329-6440-45c9-b4f7-53afff563686",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1+1j)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23eb6ba9-f0d1-42cc-96f7-5cc5440f5cc2",
   "metadata": {},
   "source": [
    "### 数值型计算"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8892616a-695e-4dfb-866f-cf27eb1e7372",
   "metadata": {},
   "source": [
    "#### 加减乘除、整除、余数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "751e672b-4ca6-4a1e-8386-0a51e234b18f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4bd12d51-845f-4f75-99a9-92f7613a2f89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 - 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0ac23b96-4881-4688-8cbc-c8d53fa7c7ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "63bab9fb-64ec-4be6-82fc-5975b3ec9840",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a34241a3-da2d-4b04-80d7-d44f2cb7a7a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 + 2 / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4100ddfc-d167-41c0-aada-391e3e05ee15",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "8d12fb7c-a8c3-4810-8b78-8f4cdc379945",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "7 % 4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b311ccf-f5bc-46a3-8815-f22832166671",
   "metadata": {},
   "source": [
    "#### 括号、赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "75fd31d4-af48-4b89-a360-9dbc822dbaba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.5"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1 + 2) / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "8021a78c-ddce-4f6a-a6e8-2e7e0beb26fb",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "cannot assign to operator (Temp/ipykernel_22652/2888965344.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/2888965344.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    1 + 1 = 2\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m cannot assign to operator\n"
     ]
    }
   ],
   "source": [
    "1 + 1 = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "74460bd5-75e2-40d4-9b34-1f559ba2e715",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4513fd87-f2af-4323-8f34-5e2a20173e08",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "940fbb59-43d5-4b70-9f38-25aab9819042",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac59ac1a-aef3-4324-8423-4daa8333c6b0",
   "metadata": {},
   "source": [
    "#### 数值比较"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3ec1c666-9fa5-47ff-b7e3-95213f153873",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 > 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "42991a5c-6dff-40cc-81eb-bec5a6e281ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 < 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "a926009d-f424-491b-b7ef-0bda5ba7aebc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "772ada3c-c47a-450d-8b58-73d618419a06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 == 1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "ceabfeb3-57d8-4c91-a94b-a7229113a4c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 != 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "454221f4-b4b2-44c2-a41d-444bedfe33e1",
   "metadata": {},
   "source": [
    "#### 变量命名、操作、见名知意、下划线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "8d74fa84-179d-428a-9213-9ce0bb61d006",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "910044ec-c7a6-459c-aed4-fa0fd3e07db5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "6dcbce6f-300d-4cc5-91c1-05055e093ceb",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = a * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "09c6e7a5-b058-4cfe-817f-241b36b220a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "83f1ccae-7253-418e-8c30-269ffd04828a",
   "metadata": {},
   "outputs": [],
   "source": [
    "a *= 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "9fbef74b-1a0e-49a4-a2f3-e694acbdfe58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "54"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "915bff69-72ef-4f0f-9be9-72eca563fce2",
   "metadata": {},
   "outputs": [],
   "source": [
    "a += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "4360425a-b70e-49e6-8cf3-09b04ee7b6c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "55"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "e146c9f5-d0c4-4354-b9a7-314bab18625a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (Temp/ipykernel_22652/167407203.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/167407203.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    1a = 3\u001b[0m\n\u001b[1;37m     ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "1a = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "e20630be-a078-43e7-9680-60f34f50c8f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "B站 = 666"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "16ef09b0-9fa6-4f5e-a836-fbe499d7c207",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "666"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B站"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d53fcf9-09dd-4bb6-8402-805303cdb8cc",
   "metadata": {},
   "source": [
    "## 布尔型"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7df24dcc-9499-4fea-937c-a3119133998d",
   "metadata": {
    "tags": []
   },
   "source": [
    "### 布尔型介绍"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7080d5df-090c-40ba-b65c-52b70aa8faa5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "06ce74c1-0bad-49f6-a060-8de853388c5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "4188f5d4-ed4b-4393-b1d4-0de876794e82",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "7100b87f-8b5a-47fe-a15e-3b98bd0ca2b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "d8932a13-0cb6-4065-9b84-1d03d731d28c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a and False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "31c39f45-057f-4aad-ae39-e133e7fe436e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "not a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96f428a3-e5a1-4e71-9c98-48b4f798ea2d",
   "metadata": {},
   "source": [
    "### 布尔型计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a7df8a66-90e6-41d8-a5c9-25413d347621",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True and True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "23dbe450-89cf-485b-8e94-c0585c0051b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True and False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "01701537-08d8-4fdd-b124-3dc554e271c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True or False"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf13aa70-1700-4987-8383-87fbdd8d3c88",
   "metadata": {},
   "source": [
    "# 逻辑判断输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14b8f81b-1ac4-4ec2-8738-9c7f060ad009",
   "metadata": {},
   "source": [
    "## 逻辑判断"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f78c392b-564b-4cb2-9d17-2a3405ec69f2",
   "metadata": {},
   "source": [
    "### if、冒号、四个空格/tab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "7a8bc1e9-6a59-4f7f-8e21-e5d4e3630e9c",
   "metadata": {},
   "outputs": [],
   "source": [
    "if True:\n",
    "    rate = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "249df59d-f508-49cd-a27d-ddfa35dfb313",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rate "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "27597600-7cad-44f1-a44d-21f1eb383d8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "if True:\n",
    "    if 2 > 1:\n",
    "        rate = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "e9bff3d2-6fa8-4f69-845a-8677714d8455",
   "metadata": {},
   "outputs": [],
   "source": [
    "if True:\n",
    " if 2 > 1:\n",
    "  rate = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "e9457376-4841-44df-8799-1632512e26c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "if False:\n",
    "    rate = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "0d68db8f-22cd-4e17-852d-0e1fc8d42bc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rate"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f719f73f-af39-4bd9-903d-fb5f1cf6f70c",
   "metadata": {},
   "source": [
    "### if elif else "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "9a4100ac-ef2e-4607-a05d-4270e6f1d924",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate = 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "b50dec7d-d4cf-4a28-a63e-4e80e97e63db",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = 0\n",
    "if gdp_rate > 0.05:\n",
    "    result = 90\n",
    "elif gdp_rate >= 0.03:\n",
    "    result = 60\n",
    "elif gdp_rate >= 0:\n",
    "    result = 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "6491d831-a134-44a7-b436-65fac94a6936",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "6098e003-8ec9-47dd-959e-5939df529f99",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = 0\n",
    "if gdp_rate > 0.05:\n",
    "    result = 90\n",
    "elif gdp_rate >= 0:\n",
    "    result = 60\n",
    "else:\n",
    "    result = 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "c74349f9-614e-442a-a186-860205b6df18",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = 0\n",
    "if gdp_rate > 0.05:\n",
    "    result = 90\n",
    "# if gdp_rate >= 0:\n",
    "    # result = 60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "6dccd760-9230-469b-8d81-955051f2d6a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "90"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfae945a-a1f9-41ef-acec-516a35733a79",
   "metadata": {},
   "source": [
    "## Python注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "842cfb63-f59f-4938-b2bf-b697aecb0ebc",
   "metadata": {},
   "source": [
    "### 单行 \\# Ctrl+/ "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "9597dd16-383f-4fa1-9f77-e046c6e6330e",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "542c762a-ee89-4091-a6e5-2d3277e7e869",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "337e9067-f697-47a2-a7e4-1a7bf1b2ac55",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "143a5d63-4861-4e5f-906b-0618d7f87a44",
   "metadata": {},
   "source": [
    "### 多行 \"\"\"或'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "59b689db-88e5-4598-9bc2-688ace4c8323",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\na = 1\\na = 2\\na = 3\\n'"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "a = 1\n",
    "a = 2\n",
    "a = 3\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8197bd46-0461-45e9-ba45-16744128b424",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "c5451c48-8df1-4015-b460-38e30ba5805d",
   "metadata": {},
   "source": [
    "## 字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7b842bd-0657-4cd8-8366-d39947846552",
   "metadata": {},
   "source": [
    "### 字符串符号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "703d9bf2-136e-4e7f-bced-5636145f1620",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速'"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"GDP增速\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "c17c739f-82af-4731-b1ea-23e30ca9142c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速'"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'GDP增速'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "403f9ab2-4edd-419a-bbb7-11b7e05070b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_text = 'GDP增速'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "3860a948-ce6f-4299-85a3-57041c95a879",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(gdp_text)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b696349e-a10d-4ca1-8221-b53e7c898da0",
   "metadata": {},
   "source": [
    "### 字符串计算拼接"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a4969e0-57f8-4750-99b0-ac8697a78a2c",
   "metadata": {},
   "source": [
    "#### 字符串计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "bde2f71f-3ae4-4edc-b20c-9b712f2bd5f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速GDP增速'"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_text * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "bdd35cf6-b60b-4552-b756-2de189e052d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速10%'"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_text + \"10%\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0a5393f-de7d-4aa2-969e-b58bb93e0cbf",
   "metadata": {},
   "source": [
    "#### 字符串和数字拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "25c853f1-acd1-4094-83db-251888aaf586",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"float\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/164300962.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mgdp_rate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mgdp_text\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mgdp_rate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"float\") to str"
     ]
    }
   ],
   "source": [
    "gdp_rate = 0.1\n",
    "gdp_text + gdp_rate"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e0ec3e0-f83e-4b3b-a9cf-9abdaf65707a",
   "metadata": {},
   "source": [
    "##### 数字转字符串的小数点问题round"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "21f1a22a-8941-4950-82d0-30f1e38e869d",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate = 0.12333"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "dca8ba7d-dc77-4891-8284-09fb631fb357",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.3"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(gdp_rate * 100, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "7bc2f817-e545-43ec-becf-c3304a2179a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate = 0.12001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "3728ed04-a765-46dc-99a6-050dc96fe439",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.0"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(gdp_rate * 100, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "09d33b5a-b2a3-4905-9d31-9adf31d18c6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp = 12330.0001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "39265fe6-d78e-4d8d-9909-06738469be6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12330.0"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(gdp, 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "563887f2-1d21-4f34-b37b-3402c60fd34d",
   "metadata": {},
   "source": [
    "##### str方法拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "810a078d-6341-465f-a1cc-327858e5e935",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(str(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "50148550-605e-4092-8de9-b55e546c94e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(int('1'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "b169faf4-80bb-4fed-8716-261eb9139657",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: '1a'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/2101436643.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'1a'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '1a'"
     ]
    }
   ],
   "source": [
    "int('1a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "a2434872-75ef-44e4-bd39-f29fae9071d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速0.1'"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_text + str(gdp_rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "2e8f65ac-7c4d-4d5e-b7b8-f58ddacd10ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate = 0.1200001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "fe8394aa-e369-4f37-aec7-89d15d8b7474",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速12.0%'"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_text + str(round(gdp_rate*100, 2))  + \"%\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efa94214-44e0-44bb-909f-d7587581034b",
   "metadata": {},
   "source": [
    "##### 字符串格式化拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "a40b4a67-27df-46c0-bacd-9c11049c8d69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 0.1'"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'GDP增速 %s' % 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "c0511c0d-2252-4ad6-91ce-5dc84e06b005",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 10.0%'"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'GDP增速 %s' % (0.1*100) + \"%\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "id": "73bd6b05-492a-442c-b4bb-76f033fbe63e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 10.00000%'"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'GDP增速 %.5f' % (0.1*100) + \"%\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "c76e9b60-85d4-4d82-9de4-43a91ef38a9e",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "incomplete format",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/1234741814.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;34m'GDP增速 %s %'\u001b[0m \u001b[1;33m%\u001b[0m \u001b[1;36m0.1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: incomplete format"
     ]
    }
   ],
   "source": [
    "'GDP增速 %s %' % 0.1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d72e676-6b8d-4ef9-83c0-4b5962b36c5f",
   "metadata": {},
   "source": [
    "##### 花括号拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "id": "8116cef8-a9cc-47f9-827e-062002759648",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 0.1 %'"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f'GDP增速 {0.1} %'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "id": "9b9e42d9-c6a6-4584-8349-1c9bce3533dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 10.0 %'"
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f'GDP增速 {10.0} %'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "id": "7e456c82-83e5-43f5-806a-0fe872af226d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 10.0 %'"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f'GDP增速 {10.00} %'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "id": "31d95325-5338-4ace-b879-e941c95c7050",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'10.00'"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_rate_text = \"%.2f\" % 10.00\n",
    "gdp_rate_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "id": "2b8a9abe-80b2-4ca7-904d-6e16e33af98b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 10.00 %'"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f'GDP增速 {gdp_rate_text} %'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "37081a92-19da-49d4-808a-b3cd63fd5cce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP增速 10.00 %'"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'GDP增速 {} %'.format(gdp_rate_text)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b328fd6-1ceb-426e-b51e-6c58e2802bdd",
   "metadata": {},
   "source": [
    "## 日期"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c529360f-2ac9-4839-badc-ea016fd12408",
   "metadata": {},
   "source": [
    "### 日期使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "47f07033-447a-4ddb-a0ee-ba3162fa8ac4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "70d0274a-0de2-4196-aee4-8cf04a6cb7fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 4, 16, 0, 0)"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime(2022, 4, 16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "id": "070336c0-93ae-40be-af09-4afaef93467d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 4, 16, 15, 0)"
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime(2022, 4, 16, 15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "id": "d9adabaf-e2b3-46ca-9ae8-9fead3985156",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "month must be in 1..12",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/3552307011.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2022\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m15\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m16\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: month must be in 1..12"
     ]
    }
   ],
   "source": [
    "datetime.datetime(2022, 15, 4, 16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "id": "fafb6cb6-ca86-4405-9556-fa300f0fe7c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 4, 16, 15, 0)"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime(year=2022, hour=15, month=4, day=16)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4760ad4d-0b77-48d5-8b99-7c144871e607",
   "metadata": {},
   "source": [
    "### 日期计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "id": "f63318f3-6869-4d7b-8d7f-dabac3013e85",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = datetime.datetime(year=2022, hour=15, month=4, day=16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "id": "b439219a-416b-49b7-b89d-c413b0cc14e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = datetime.datetime(year=2022, hour=15, month=4, day=21)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "id": "8e21212b-e210-4297-b84a-7368d7ed6f7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.timedelta(days=5)"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b - a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "id": "88465421-b21c-4d86-9aa6-ee812c158c6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 5, 1, 15, 0)"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b + datetime.timedelta(days=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "84a0af20-4624-41db-9457-4c7999c0f33f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2022"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "id": "bd29648b-b3c0-49bb-82f1-c6c7585303b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "id": "edc20783-e108-4f33-88f6-64389d4d751b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 4, 17, 2, 14, 11, 420038)"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime.now()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c71caa41-70df-431e-814a-f5462d198a28",
   "metadata": {},
   "source": [
    "## 模式初现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "52f95ab4-fd80-4e44-8ab8-fb3a49e3e47e",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_2022 = 12222\n",
    "gdp_2021 = 13333"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "524f9784-176d-4b15-9b4e-e73177c97c22",
   "metadata": {},
   "source": [
    "A 指标全年xx，比上年增加/减少xx，比上年增长/减少xx.x%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "5d84d7b2-1cd0-47cf-b25e-cfbe92e6185f",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_2022_increase = gdp_2022 - gdp_2021\n",
    "gdp_2022_rate = gdp_2022_increase / gdp_2021\n",
    "\n",
    "if gdp_2022_increase > 0:\n",
    "    gdp_judge = \"增长\"\n",
    "elif gdp_2022_increase < 0:\n",
    "    gdp_judge = \"下降\"\n",
    "else:\n",
    "    gdp_judge = \"变化\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "09738d6c-96b1-418b-8dd3-ed8015b5ace3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP全年12222万亿，比上年下降1111万亿，比上年下降8.33%'"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f\"GDP全年{gdp_2022}万亿，比上年{gdp_judge}{abs(gdp_2022_increase)}万亿，\\\n",
    "比上年{gdp_judge}{'%.2f' % (abs(gdp_2022_rate)*100)}%\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b36f9401-e50a-4568-b6a0-ce07219c7a5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e24d77f2-656e-4327-9ed9-8d5bf7d2d100",
   "metadata": {},
   "source": [
    "# 时序截面取数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efbdd1a3-a9d1-435f-b602-390433366a8d",
   "metadata": {},
   "source": [
    "容器：list dict set tuple"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5463eb05-125a-45ba-abff-0286abcc3ea5",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 列表list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "7674a0f8-2928-41fd-91be-2a650af5c234",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_2022 = 14444\n",
    "gdp_2021 = 13333\n",
    "gdp_2020 = 12222\n",
    "gdp_2019 = 11111\n",
    "gdp_2018 = 10000"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69949eb4-ef3f-4d8e-8c69-a2dad0a1057f",
   "metadata": {},
   "source": [
    "### 新建、类型转换、追加"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c95e3fec-0f81-4aad-954f-aa55ba71c7f3",
   "metadata": {},
   "source": [
    "#### 新建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "f164bd52-e789-4abc-aef6-cccf006ec839",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_list = [1, 2, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "2ccd5364-78af-4ed1-a863-aacc4cc2d57e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bccc9e9-4eaf-4db6-b887-577a99a7e284",
   "metadata": {},
   "source": [
    "#### 类型转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "46f39a49-5263-411e-ac17-16d7fb4363a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list([1, 2, 3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "0f736502-fef4-4908-893e-cca8f53c55a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list({1, 2, 3})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "282aa46d-daaf-4eb2-b44a-52c48187e22c",
   "metadata": {},
   "source": [
    "#### 追加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "id": "c2d889ae-0a3e-4649-9d65-62e3ae1669b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "id": "80ad9ea1-9c75-4e42-b7d5-640e07a13973",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_list.append(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "22bc1b6c-f401-4a45-b3b1-4c008bfed50e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 229,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "id": "e6c73566-2c39-40c6-b84f-0ade5f4c8c32",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_list.append(\"你好\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "id": "82bf76da-b95b-44f5-8439-a4af984ea101",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, '你好']"
      ]
     },
     "execution_count": 231,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "927b3f05-b124-444b-96b6-1fe848135067",
   "metadata": {},
   "source": [
    "### 索引、替换、切片"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9a57b90-3de1-48c9-b399-b5079cbefe86",
   "metadata": {},
   "source": [
    "#### 索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "c0b31d97-ecf4-4c23-9192-ede2b44045e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, '你好']"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "cc5886ac-289a-44ef-ab8b-f294419d2eaa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "id": "0128694d-356b-462f-a5d9-7a7b11936327",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 234,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "id": "543f8c8c-71a0-4a0f-981f-68daf77eeab0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好'"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "id": "1a3acf95-d5e2-4b2b-b59c-cf4156747d9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 236,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[-2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccfca8be-aa3a-4d82-96fd-373480c5d4e5",
   "metadata": {},
   "source": [
    "#### 替换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "id": "c6373eab-a0cc-4e98-b752-c1649c07b48b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 288,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "id": "e695085d-e182-4453-a6ab-1f198377429d",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_list[0] = 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "id": "c89ebf45-5c89-4a62-9671-ed4e0a76617c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100, 2, 3]"
      ]
     },
     "execution_count": 290,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db2946ae-4386-471d-b455-e42ff3e9e93b",
   "metadata": {},
   "source": [
    "#### 切片"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e6f37bb-dd8f-4e7c-8841-020ea8245b5c",
   "metadata": {},
   "source": [
    "冒号、左闭右开"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 238,
   "id": "d6973b85-88fa-4da3-81bd-02f4c82ede0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, '你好']"
      ]
     },
     "execution_count": 238,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "id": "8e8b53b9-4b34-4819-a70b-35963e79a0ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4]"
      ]
     },
     "execution_count": 239,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "id": "c2924346-5fc6-476a-ba28-3b192d20c2de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 240,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list[:-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6676a959-8ad7-4332-87de-e9e522051ed9",
   "metadata": {},
   "source": [
    "### 长度、删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "id": "a616b1ae-bf2c-4b9f-875b-7e370edadb00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(a_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "id": "98c97aae-0504-451c-847a-6a7a8158ae75",
   "metadata": {},
   "outputs": [],
   "source": [
    "del a_list[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 245,
   "id": "2de179a4-3ce3-479c-9e9a-fdc6f43e88e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 245,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13aab9f7-8aef-472c-84bc-08d50692e714",
   "metadata": {},
   "source": [
    "### 包含判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "id": "a196ada1-c236-4eab-ac33-0b2e9daba453",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 247,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 in a_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 248,
   "id": "0e8329b2-17df-41e8-9cac-cc51bf5efd8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 248,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in a_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c99f6d8a-a9ea-4886-bf57-3b206d72f787",
   "metadata": {},
   "source": [
    "### range"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8fb2a396-5b70-4059-94d4-f7dc20f1fa2e",
   "metadata": {},
   "source": [
    "左闭右开"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "id": "106646e1-b575-4814-8026-1be69b0bca21",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 249,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[0, 1, 2, 3, 4, 5, 6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "id": "115fe701-ab0b-419a-837d-9c5b43dbf1c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 6)"
      ]
     },
     "execution_count": 250,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 254,
   "id": "d38163d8-91a3-43e8-8eb8-2502cada399e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 6)"
      ]
     },
     "execution_count": 254,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0, 6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "id": "8c600f24-4fce-46b8-a3a1-ef6cccc06439",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 6, 2)"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0, 6, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "id": "d01e040b-32c1-49ac-b2d8-0c5653ffa40e",
   "metadata": {},
   "outputs": [],
   "source": [
    "r_list = range(0, 6, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 262,
   "id": "34e567db-1f10-40d1-b885-ef6f3ab8ef69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 262,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(r_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "a6d8968c-8820-4931-91f6-0461bf752161",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 3)"
      ]
     },
     "execution_count": 264,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_list[0], r_list[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34b47bc2-1de7-4578-9b7a-5146dc611ac5",
   "metadata": {},
   "source": [
    "## 字典dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "id": "3be2657c-823d-4399-8a05-4ebbeb58eb22",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_2022 = 14444\n",
    "gdp_2022_1 = 4444\n",
    "gdp_2022_2 = 4000\n",
    "gdp_2022_3 = 6000"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b42a64e-ca73-427a-801c-571eb4f669c8",
   "metadata": {},
   "source": [
    "### 新建、增加、修改"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe09d6ce-e7de-40d5-ab29-cc6874e6406c",
   "metadata": {},
   "source": [
    "{key: value}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9df63e8-da8e-4bb7-8943-2bb461221508",
   "metadata": {},
   "source": [
    "#### 新建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "id": "eac95c10-1aee-4e12-b859-684b1c92c22b",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_dict = {\"2022年GDP\": 14444,\"第一产业\": 4444, \"第二产业\": 4000, \"第三产业\": 6000}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 274,
   "id": "bd7c72a2-9dd7-46f6-bf13-b2fa0acf61d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444, '第一产业': 4444, '第二产业': 4000, '第三产业': 6000}"
      ]
     },
     "execution_count": 274,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 275,
   "id": "bd7e81dd-b123-46fe-a627-16a2552577ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 275,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 280,
   "id": "e009012e-59d9-44f1-bff7-a82197d13a2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'x': 1, 'y': 2}"
      ]
     },
     "execution_count": 280,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict(x=1, y=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0944cf5c-76ad-4314-9fcb-7ba9c14cfb2e",
   "metadata": {},
   "source": [
    "#### 增加、替换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 284,
   "id": "60b5bdec-4141-48be-a733-33c20b256f3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_dict['第四产业'] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "id": "f8e9adbe-d5b7-4dcb-a802-d01c273d8444",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444, '第一产业': 4444, '第二产业': 4000, '第三产业': 6000, '第四产业': 0}"
      ]
     },
     "execution_count": 285,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 286,
   "id": "c542c06d-f9ea-4126-9608-f59757f84592",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_dict['第四产业'] = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 287,
   "id": "e4ce2267-760b-4731-97a3-64d8df82f26c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444, '第一产业': 4444, '第二产业': 4000, '第三产业': 6000, '第四产业': 10}"
      ]
     },
     "execution_count": 287,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "id": "e83a2c77-ca64-4d5d-82b5-5b1c756e9648",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.setdefault('第四产业', 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "id": "08dcad1c-6981-4649-81bd-b51f49a27683",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444, '第一产业': 4444, '第二产业': 4000, '第三产业': 6000, '第四产业': 10}"
      ]
     },
     "execution_count": 292,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 293,
   "id": "0a73b79e-8bd3-434f-b36e-dff89a7c1559",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 293,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.setdefault('第五产业', 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 294,
   "id": "aac49d21-f684-44b9-b19b-3c29f32cffb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444,\n",
       " '第一产业': 4444,\n",
       " '第二产业': 4000,\n",
       " '第三产业': 6000,\n",
       " '第四产业': 10,\n",
       " '第五产业': 100}"
      ]
     },
     "execution_count": 294,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6c608f6-8d96-42f6-808f-bd4a61222572",
   "metadata": {},
   "source": [
    "### 字典取数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 295,
   "id": "83913c96-e121-4b06-8530-3293c7d09b77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 295,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict['第四产业']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 297,
   "id": "cc5b1179-d2f4-4b99-a04f-54dd08b14212",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'第六产业'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/2258510311.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma_dict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'第六产业'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: '第六产业'"
     ]
    }
   ],
   "source": [
    "a_dict['第六产业']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 298,
   "id": "eb20dce1-2c05-4b99-ac7b-46d24fb0e878",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "666"
      ]
     },
     "execution_count": 298,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.get('第六产业', 666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 299,
   "id": "e274b62b-e5b6-43b0-bb22-d676d2eea9f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 299,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.get('第四产业', 666)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fef8b5ef-f18e-4502-b5fa-cf0c1e26b604",
   "metadata": {},
   "source": [
    "#### key和value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 302,
   "id": "6a780005-5046-4cb9-9974-bbb4a470e8ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['2022年GDP', '第一产业', '第二产业', '第三产业', '第四产业', '第五产业'])"
      ]
     },
     "execution_count": 302,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 305,
   "id": "ab895a13-18a2-4eae-822f-b72a71fe2ad3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 305,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'第一产业' in a_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 304,
   "id": "ea238db3-154a-40ff-beca-2940f9eea3f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['2022年GDP', '第一产业', '第二产业', '第三产业', '第四产业', '第五产业']"
      ]
     },
     "execution_count": 304,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(a_dict.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 303,
   "id": "86dcf844-16fe-4ee5-8f49-a9c3f09b0835",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values([14444, 4444, 4000, 6000, 10, 100])"
      ]
     },
     "execution_count": 303,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.values()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b43f382d-c559-4397-8525-0ca9863f428f",
   "metadata": {},
   "source": [
    "### 长度、删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 306,
   "id": "d12a7d83-18c3-4abb-998f-ed1cef78f880",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444,\n",
       " '第一产业': 4444,\n",
       " '第二产业': 4000,\n",
       " '第三产业': 6000,\n",
       " '第四产业': 10,\n",
       " '第五产业': 100}"
      ]
     },
     "execution_count": 306,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 301,
   "id": "4b0df1ef-eede-4819-9302-133a22619ae3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 301,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(a_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 307,
   "id": "87ec27de-8e60-4674-a58a-26c83aad8200",
   "metadata": {},
   "outputs": [],
   "source": [
    "del a_dict['第五产业']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 308,
   "id": "4b249bdc-a813-4505-872b-4936e8cff253",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444, '第一产业': 4444, '第二产业': 4000, '第三产业': 6000, '第四产业': 10}"
      ]
     },
     "execution_count": 308,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "526c127d-a5e8-46d5-88bd-9fcbf6bd8d77",
   "metadata": {},
   "source": [
    "### 包含判断"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6831331-510a-494f-abb0-a03779674636",
   "metadata": {},
   "source": [
    "字典包含默认key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 309,
   "id": "f2c2fd44-5371-4925-80af-e316a5cd2ff4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 309,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'第一产业' in a_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "id": "75e70a71-81b7-4f9b-ba05-f06b0ecdd792",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 310,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'第一产业' in a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "id": "b9e6c483-7f04-4ebe-83ee-03ed01455d57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 311,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4444 in a_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 312,
   "id": "443ffe3f-0546-48e3-b589-e94437ce4ee3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 312,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4444 in a_dict.values()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d165465-0045-41a3-b958-601a4083eb10",
   "metadata": {},
   "source": [
    "### 组合字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 319,
   "id": "7b5bbb22-200e-407e-a780-522ee4d074e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "b_dict = {\n",
    " 'GDP': [14444, 13333, 12222],\n",
    " '第一产业': [4444, 3333, 2222],\n",
    " '第二产业': [4000, 4000, 4000],\n",
    " '第三产业': [6000, 6000, 6000],\n",
    " '年份': [2022, 2021, 2020]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 320,
   "id": "739aea3b-b33b-48a1-847a-e6c8f7816aa2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'GDP': [14444, 13333, 12222],\n",
       " '第一产业': [4444, 3333, 2222],\n",
       " '第二产业': [4000, 4000, 4000],\n",
       " '第三产业': [6000, 6000, 6000],\n",
       " '年份': [2022, 2021, 2020]}"
      ]
     },
     "execution_count": 320,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 321,
   "id": "2bdb997c-997e-4e6b-b08f-f74483043b2f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 322,
   "id": "ef641acd-2f9c-4b8e-8aea-63491807709d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GDP</th>\n",
       "      <th>第一产业</th>\n",
       "      <th>第二产业</th>\n",
       "      <th>第三产业</th>\n",
       "      <th>年份</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>14444</td>\n",
       "      <td>4444</td>\n",
       "      <td>4000</td>\n",
       "      <td>6000</td>\n",
       "      <td>2022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13333</td>\n",
       "      <td>3333</td>\n",
       "      <td>4000</td>\n",
       "      <td>6000</td>\n",
       "      <td>2021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12222</td>\n",
       "      <td>2222</td>\n",
       "      <td>4000</td>\n",
       "      <td>6000</td>\n",
       "      <td>2020</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     GDP  第一产业  第二产业  第三产业    年份\n",
       "0  14444  4444  4000  6000  2022\n",
       "1  13333  3333  4000  6000  2021\n",
       "2  12222  2222  4000  6000  2020"
      ]
     },
     "execution_count": 322,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(b_dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c6a05d5-ab30-4aa8-892e-25efc125fc7e",
   "metadata": {},
   "source": [
    "## 集合set"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2119c16a-23f5-4e93-abce-3fcd87167e90",
   "metadata": {},
   "source": [
    "### 新建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 325,
   "id": "ccba5342-4b9d-44d5-9f7a-635adced3cb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_set = {1, 1, 2}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 326,
   "id": "c8954e8f-511f-4054-b83e-1a5a956d8197",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2}"
      ]
     },
     "execution_count": 326,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 327,
   "id": "a33ba0fc-6e78-426b-881a-780341ba75f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "set"
      ]
     },
     "execution_count": 327,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 328,
   "id": "6b03b88a-cfd1-4975-872c-0eaecda1254f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'b'}"
      ]
     },
     "execution_count": 328,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(['a', 'a', 'b'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74d1e439-d635-433e-bf37-4668effbe922",
   "metadata": {},
   "source": [
    "### 计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 330,
   "id": "bf38b509-068a-4030-9c7f-3853aa55a32f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2}"
      ]
     },
     "execution_count": 330,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 332,
   "id": "e83f4afa-bd60-48db-93e0-f8b124654d92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{2, 3, 4}"
      ]
     },
     "execution_count": 332,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b_set = {2,3,4}\n",
    "b_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 333,
   "id": "e1e80034-3fce-43be-98c3-d7f5389fa4e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1}"
      ]
     },
     "execution_count": 333,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_set - b_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 336,
   "id": "57b80a10-c3da-4934-a712-6d480269535d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{2}"
      ]
     },
     "execution_count": 336,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_set.intersection(b_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 337,
   "id": "803956ac-31f0-4f52-8c70-780a6cd454b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4}"
      ]
     },
     "execution_count": 337,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_set.union(b_set)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1fb25064-901d-4afd-b9fa-59d0c950a5a4",
   "metadata": {},
   "source": [
    "## 元组tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 339,
   "id": "ffa4e961-5192-423b-9de5-ab3b70dffad0",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_tpl = (1, 2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 344,
   "id": "836ba446-c9d8-425b-9f6c-7c72202c2af2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 344,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_tpl[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 345,
   "id": "af211f13-5abe-414a-a405-f2c26e97e622",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/1667895178.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma_tpl\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "a_tpl[2] = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 348,
   "id": "e0fdd95c-fcbf-4a37-a606-4cc3e3962188",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3)"
      ]
     },
     "execution_count": 348,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_tpl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 349,
   "id": "79239d4e-9458-42d8-8171-071f344ca9bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 1, 1)"
      ]
     },
     "execution_count": 349,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1, 1, 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 350,
   "id": "13b2528f-a8df-4fff-886b-4dd717444799",
   "metadata": {},
   "outputs": [],
   "source": [
    "a, b, c = (1, 1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 351,
   "id": "6dacae03-4c4f-4555-820e-c31f740004ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 351,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 352,
   "id": "2827de2c-7c65-45b8-9575-924867506895",
   "metadata": {},
   "outputs": [],
   "source": [
    "a, b, c = [1, 1, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 353,
   "id": "bd76ac2e-c4fb-406f-b5c0-4131ff6c9cf3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 353,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0aa57b0-b947-47b3-836a-8def50a03a8a",
   "metadata": {},
   "source": [
    "# 复杂语句输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab9b48f0-89c9-4a0f-8dfe-cc05f5365498",
   "metadata": {},
   "source": [
    "## 循环逻辑"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 356,
   "id": "752f16ab-3aa6-4f24-87ed-212a85eb4699",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp = [14444, 13333, 12222, 11111, 10000, 9999]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57e85bc9-b2cb-463d-b6c6-7ae668f2036e",
   "metadata": {},
   "source": [
    "本年GDP增速达到近几年的新高/低"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8516e985-13e3-41fd-8cdd-98ca7a816c1f",
   "metadata": {},
   "source": [
    "### for while print"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "875ca0d6-50f0-48f3-a4f0-aae3de128d17",
   "metadata": {},
   "source": [
    "for倾向于对容器    \n",
    "while倾向于对条件"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b00aa911-af83-4c20-9bd9-022b5e9285af",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### for"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80c39000-0543-478a-b22f-e13c8b04e064",
   "metadata": {},
   "source": [
    "容器从开始到结束遍历"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b53e108-55a6-4887-8928-62a6891bf79e",
   "metadata": {},
   "source": [
    "##### 列表和for"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 358,
   "id": "f139d373-fde9-4692-af4c-4a374bf13c84",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in gdp:\n",
    "    i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 357,
   "id": "f122045a-40af-426a-be7c-3b33891d46c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14444\n",
      "13333\n",
      "12222\n",
      "11111\n",
      "10000\n",
      "9999\n"
     ]
    }
   ],
   "source": [
    "for i in gdp:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 361,
   "id": "582327f2-8381-442b-8697-c1a0a90f5410",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14444\n",
      "13333\n",
      "12222\n",
      "11111\n",
      "10000\n",
      "9999\n"
     ]
    }
   ],
   "source": [
    "for item in gdp:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4a3b92a-ffde-4969-91f0-524144a8f556",
   "metadata": {},
   "source": [
    "##### 字典和for"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 362,
   "id": "377ca8c6-be7a-49d5-af4d-0a10f4539379",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'2022年GDP': 14444, '第一产业': 4444, '第二产业': 4000, '第三产业': 6000, '第四产业': 10}"
      ]
     },
     "execution_count": 362,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 363,
   "id": "a04a880f-fea7-4797-8214-9be091f13ed4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022年GDP\n",
      "第一产业\n",
      "第二产业\n",
      "第三产业\n",
      "第四产业\n"
     ]
    }
   ],
   "source": [
    "for item in a_dict:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 364,
   "id": "46e8d182-56ef-482a-a176-bc901e7220d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_items([('2022年GDP', 14444), ('第一产业', 4444), ('第二产业', 4000), ('第三产业', 6000), ('第四产业', 10)])"
      ]
     },
     "execution_count": 364,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_dict.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 365,
   "id": "9b0ae18d-6f6d-4355-81c3-7187c8d819e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022年GDP 14444\n",
      "第一产业 4444\n",
      "第二产业 4000\n",
      "第三产业 6000\n",
      "第四产业 10\n"
     ]
    }
   ],
   "source": [
    "for k, v in a_dict.items():\n",
    "    print(k, v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 366,
   "id": "ce79ac99-0e4c-4a3e-8e4c-32c5103cc873",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14444\n",
      "4444\n",
      "4000\n",
      "6000\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "for v in a_dict.values():\n",
    "    print(v)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c72dd260-4bee-4b0a-8a8a-c21d5c532be7",
   "metadata": {},
   "source": [
    "#### while"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 371,
   "id": "4a08105e-a7f2-4aa5-806b-d086b3bbbd8b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "a = 0\n",
    "while a != 3:\n",
    "    # a = a+1\n",
    "    print(a)\n",
    "    a += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 370,
   "id": "a277ee28-e82b-467e-827c-e9a3c46695a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 370,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11f5f659-c506-4f9d-a059-77b21d2119a3",
   "metadata": {},
   "source": [
    "### break continue"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c2305e4-d065-459c-be26-dbb7f21e1e70",
   "metadata": {},
   "source": [
    "#### break 中断跳出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 373,
   "id": "f5dacd14-50c2-443a-8e51-1ad97278a8b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "条件满足\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "    if i > 1:\n",
    "        print(i)\n",
    "        print('条件满足')\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6aca912-a769-4d58-8a82-0c38fc2bf87c",
   "metadata": {},
   "source": [
    "#### continue 继续回到开头执行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 375,
   "id": "31d03ed0-c5a0-416d-971f-887ee34f893a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这是最后一行\n",
      "2\n",
      "条件满足\n",
      "3\n",
      "条件满足\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "    if i > 1:\n",
    "        print(i)\n",
    "        print('条件满足')\n",
    "        continue\n",
    "    print('这是最后一行')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17085bf8-aad1-464f-9654-2fb1997c4e71",
   "metadata": {},
   "source": [
    "### enumerate，zip"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cee85fb8-aba0-4340-85d7-40242c659233",
   "metadata": {},
   "source": [
    "#### enumerate，生成索引和值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 376,
   "id": "df058832-4e9c-4deb-9d67-6e9015be2c29",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "222\n",
      "333\n",
      "444\n"
     ]
    }
   ],
   "source": [
    "for i in [222, 333, 444]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 377,
   "id": "2e573549-a5f8-48bb-93b1-3ecfb102cfd6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 222\n",
      "1 333\n",
      "2 444\n"
     ]
    }
   ],
   "source": [
    "for idx, i in enumerate([222, 333, 444]):\n",
    "    print(idx, i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26403889-5a80-4d4f-9041-5bee551d5597",
   "metadata": {},
   "source": [
    "#### zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 378,
   "id": "388e3347-a455-48ab-a09a-f368b16ffa5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'GDP': [14444, 13333, 12222],\n",
       " '第一产业': [4444, 3333, 2222],\n",
       " '第二产业': [4000, 4000, 4000],\n",
       " '第三产业': [6000, 6000, 6000],\n",
       " '年份': [2022, 2021, 2020]}"
      ]
     },
     "execution_count": 378,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 379,
   "id": "013de0b2-f8ea-47b6-8339-4b7ab128d0e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022\n",
      "2021\n",
      "2020\n"
     ]
    }
   ],
   "source": [
    "for i in b_dict['年份']:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 380,
   "id": "39caef7b-1881-4911-9cdc-611742abcd1b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14444\n",
      "13333\n",
      "12222\n"
     ]
    }
   ],
   "source": [
    "for i in b_dict['GDP']:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 381,
   "id": "6222a58f-0b7f-41ce-aac3-6cd3f67402b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022 14444\n",
      "2021 13333\n",
      "2020 12222\n"
     ]
    }
   ],
   "source": [
    "for year, gdp in zip(b_dict['年份'], b_dict['GDP']) :\n",
    "    print(year, gdp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 383,
   "id": "71f4db6e-0510-484f-a85b-f792525a97d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 383,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(b_dict['年份'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 384,
   "id": "aabd5d93-32d7-4194-84ce-c176991ad1ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 3)"
      ]
     },
     "execution_count": 384,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(len(b_dict['年份']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 385,
   "id": "d9c68ec5-35c4-45b4-bf4f-b51ee5573708",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022 14444\n",
      "2021 13333\n",
      "2020 12222\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(b_dict['年份'])):\n",
    "    print(b_dict['年份'][i], b_dict['GDP'][i])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0fd0e8e-acea-4040-94d8-44224d15ab8a",
   "metadata": {},
   "source": [
    "## 模式输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 448,
   "id": "b9d24c59-8359-4416-8e00-97bf4bf47c14",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA = {'GDP': [14444, 13333, 12222, 10611, 10000, 8888, 7777],\n",
    " '第一产业': [4444, 3333, 2222, 2111, 2000, 1888, 1277],\n",
    " '第二产业': [4000, 4000, 4000, 4500, 4000, 3000, 2750],\n",
    " '第三产业': [6000, 6000, 6000, 4000, 4000, 4000, 3750],\n",
    " '年份': [2022, 2021, 2020, 2019, 2018, 2017, 2016]}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b88f43b3-72ff-4f40-a302-05ca8037f637",
   "metadata": {},
   "source": [
    "### 时序数据：增速达到近x年来最大/小值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ea2640c-e085-4467-a8ff-ccb232e99a80",
   "metadata": {},
   "source": [
    "#### 计算增速"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 449,
   "id": "a4eb8b2f-3c89-48a3-94db-c69fdcb4778c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[14444, 13333, 12222, 10611, 10000, 8888, 7777]"
      ]
     },
     "execution_count": 449,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA['GDP']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 451,
   "id": "903dca2b-6539-415a-9373-6c6e34c0f789",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.08332708317707938"
      ]
     },
     "execution_count": 451,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA['GDP'][0] / DATA['GDP'][1] - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 452,
   "id": "afb3d9a2-826d-4af2-8575-13ca11d1662d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09090165275732276"
      ]
     },
     "execution_count": 452,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA['GDP'][1] / DATA['GDP'][2] - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 455,
   "id": "f2c21963-59bf-49a5-a274-831df3a46839",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 455,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "length = len(DATA['GDP'])\n",
    "length"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 450,
   "id": "e123d4eb-d76a-49df-8438-5d5ec29b1aaa",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate_list = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 458,
   "id": "aa5e430d-5dde-43d3-89f3-31601d94fa3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "for i in range(length):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 463,
   "id": "28def26f-cca4-4002-a3d1-2e02df280882",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_rate_list = []\n",
    "for i in range(length-1):\n",
    "    gdp_rate = DATA['GDP'][i] / DATA['GDP'][i+1] - 1\n",
    "    gdp_rate_list.append(gdp_rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 464,
   "id": "8de63a10-993f-4b74-b1a9-4484e804d24c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.08332708317707938,\n",
       " 0.09090165275732276,\n",
       " 0.1518235793044953,\n",
       " 0.06109999999999993,\n",
       " 0.1251125112511251,\n",
       " 0.1428571428571428]"
      ]
     },
     "execution_count": 464,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_rate_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "956d2e13-3bf3-4599-8397-10bd67fb2c54",
   "metadata": {},
   "source": [
    "#### 判断最大/最小增速和持续时间"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "039a2c7f-de49-4b43-89eb-3354ef8b1d3e",
   "metadata": {},
   "source": [
    "增速达到近x年来最大/小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 468,
   "id": "22643ead-50cb-4c3c-a61c-e3c6b9a66903",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 0.06109999999999993\n"
     ]
    }
   ],
   "source": [
    "judge_inc_dec = \"\"\n",
    "continue_year = 0\n",
    "\n",
    "if gdp_rate_list[0] > gdp_rate_list[1]:\n",
    "    judge_inc_dec = \"最大值\"\n",
    "    for idx, tmp_rate in enumerate(gdp_rate_list):\n",
    "        if gdp_rate_list[0] < tmp_rate:\n",
    "            continue_year = idx\n",
    "            print(idx, tmp_rate)\n",
    "            break\n",
    "elif gdp_rate_list[0] < gdp_rate_list[1]:\n",
    "    judge_inc_dec = \"最小值\"\n",
    "    for idx, tmp_rate in enumerate(gdp_rate_list):\n",
    "        if gdp_rate_list[0] > tmp_rate:\n",
    "            continue_year = idx\n",
    "            print(idx, tmp_rate)\n",
    "            break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 469,
   "id": "f00d6eb3-add3-4788-89cb-2bc118c5abbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('最小值', 3)"
      ]
     },
     "execution_count": 469,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "judge_inc_dec, continue_year"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af332f2b-d301-432c-9af0-d1776b052d99",
   "metadata": {},
   "source": [
    "#### 文本输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 470,
   "id": "cad67bad-4474-4bba-991b-2f49d06bbbbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'增速达到近3年来最小值'"
      ]
     },
     "execution_count": 470,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f\"增速达到近{continue_year}年来{judge_inc_dec}\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45173c0b-a141-4871-8902-686a9b648d1d",
   "metadata": {},
   "source": [
    "### 截面数据：A1指标占A指标xx.x%，A2指标占A指标xx.x%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 448,
   "id": "8b7dffa9-59cc-4d7f-b667-828ae83b4fc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA = {'GDP': [14444, 13333, 12222, 10611, 10000, 8888, 7777],\n",
    " '第一产业': [4444, 3333, 2222, 2111, 2000, 1888, 1277],\n",
    " '第二产业': [4000, 4000, 4000, 4500, 4000, 3000, 2750],\n",
    " '第三产业': [6000, 6000, 6000, 4000, 4000, 4000, 3750],\n",
    " '年份': [2022, 2021, 2020, 2019, 2018, 2017, 2016]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 471,
   "id": "adca6a82-0e68-440f-a134-bdfc5c41b36f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GDP\n",
      "第一产业\n",
      "第二产业\n",
      "第三产业\n",
      "年份\n"
     ]
    }
   ],
   "source": [
    "for key in DATA:\n",
    "    print(key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 472,
   "id": "e720e27b-ba1f-43df-8e33-74240e0bd188",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一产业\n",
      "第二产业\n",
      "第三产业\n"
     ]
    }
   ],
   "source": [
    "for key in DATA:\n",
    "    if key == 'GDP' or key == '年份':\n",
    "        continue\n",
    "    print(key)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00f5eb30-bebc-467a-9aec-d075feb16474",
   "metadata": {},
   "source": [
    "#### 字符串也是列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 478,
   "id": "29cc514e-85f6-43aa-bd10-a2d875ac86dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业占GDP1%，第二产业占GDP1%，第三产业占GDP1%'"
      ]
     },
     "execution_count": 478,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_text = \"\"\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_text = f\"{key}占GDP{1}%\"\n",
    "    total_text = total_text + tmp_text + \"，\"\n",
    "total_text[:-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57175887-49e2-4e5a-90aa-9afb97f151ff",
   "metadata": {},
   "source": [
    "#### 用判断的形式构造，if和list的应用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 481,
   "id": "8bb5885d-06e7-46f1-a437-3e39fbcb0ae4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业占GDP1%，第二产业占GDP1%，第三产业占GDP1%'"
      ]
     },
     "execution_count": 481,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_text = \"\"\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_text = f\"{key}占GDP{1}%\"\n",
    "    if total_text == \"\":\n",
    "        total_text = tmp_text\n",
    "    else:\n",
    "        total_text = total_text + \"，\" + tmp_text\n",
    "total_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 485,
   "id": "7cd52efd-7455-49ea-aa74-44507719cf53",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "total_text = \"abc\"\n",
    "if total_text:\n",
    "    print(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 486,
   "id": "b178b1bd-8175-4643-b1aa-5bbe0d06cde5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业占GDP1%，第二产业占GDP1%，第三产业占GDP1%'"
      ]
     },
     "execution_count": 486,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_text = \"\"\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_text = f\"{key}占GDP{1}%\"\n",
    "    if total_text: # 如果有值\n",
    "        total_text = total_text + \"，\" + tmp_text\n",
    "    else: # 如果没有值\n",
    "        total_text = tmp_text\n",
    "total_text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e02a159c-5ffa-4a08-af21-a08d45a5df87",
   "metadata": {},
   "source": [
    "#### 最终输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 487,
   "id": "1d00a3f6-6218-4496-97ab-310574340c60",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业占GDP30.77%，第二产业占GDP27.69%，第三产业占GDP41.54%'"
      ]
     },
     "execution_count": 487,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_text = \"\"\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_rate = DATA[key][0] / DATA[\"GDP\"][0] * 100\n",
    "    tmp_text = f\"{key}占GDP{'%.2f' % tmp_rate}%\"\n",
    "    if total_text: # 如果有值\n",
    "        total_text = total_text + \"，\" + tmp_text\n",
    "    else: # 如果没有值\n",
    "        total_text = tmp_text\n",
    "total_text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "391c1cb5-7830-4f39-9412-d66521b4f487",
   "metadata": {},
   "source": [
    "### 面板数据： A1增长贡献排名第一，增长xx.x%，拉动A指标增长xx.x%!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 448,
   "id": "09d152b1-b193-422b-8148-4ec8e11ab444",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA = {'GDP': [14444, 13333, 12222, 10611, 10000, 8888, 7777],\n",
    " '第一产业': [4444, 3333, 2222, 2111, 2000, 1888, 1277],\n",
    " '第二产业': [4000, 4000, 4000, 4500, 4000, 3000, 2750],\n",
    " '第三产业': [6000, 6000, 6000, 4000, 4000, 4000, 3750],\n",
    " '年份': [2022, 2021, 2020, 2019, 2018, 2017, 2016]}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03a3ae28-11f0-4c01-b838-86adea219d74",
   "metadata": {},
   "source": [
    "增长贡献第一：增量最大的A1 : $\\Delta A1$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a47cc36-530e-4c86-a049-ce851af99117",
   "metadata": {},
   "source": [
    "拉动增长计算：$\\frac{\\Delta GDP}{GDP_{last}} \\times \\frac{\\Delta A1}{\\Delta GDP} = \\frac{\\Delta A1}{GDP_{last}}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 489,
   "id": "ad5309a3-1478-4bfb-ab3a-705b4ff8489b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1111"
      ]
     },
     "execution_count": 489,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_inc = 0\n",
    "\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_inc = DATA[key][0] - DATA[key][1]\n",
    "    if tmp_inc > max_inc: # 如果当前的子项更大\n",
    "        max_inc = tmp_inc\n",
    "max_inc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 491,
   "id": "59cd33cd-8a2c-45ee-876e-4ea606624764",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1111, '第一产业', 8.332708317707944, 33.33333333333333)"
      ]
     },
     "execution_count": 491,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_inc, max_key, max_push, max_rate = 0, \"\", 0, 0\n",
    "\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_inc = DATA[key][0] - DATA[key][1]\n",
    "    if tmp_inc > max_inc: # 如果当前的子项增量更大\n",
    "        max_inc = tmp_inc\n",
    "        max_key = key\n",
    "        max_push = tmp_inc / DATA[\"GDP\"][1] * 100\n",
    "        max_rate = tmp_inc / DATA[key][1] * 100\n",
    "max_inc, max_key, max_push, max_rate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 492,
   "id": "69746841-b831-4872-a857-9d2d5f30b661",
   "metadata": {},
   "outputs": [],
   "source": [
    "total_text = f\"{max_key}增长贡献排名第一，\\\n",
    "增长{'%.2f' % max_rate}%，拉动GDP增长{'%.2f' % max_push}%!\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 493,
   "id": "d7d2bb47-7339-416f-86fd-cc1a540ac17f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业增长贡献排名第一，增长33.33%，拉动GDP增长8.33%!'"
      ]
     },
     "execution_count": 493,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64f41806-f8e3-4beb-a553-20d8e1c743dc",
   "metadata": {},
   "source": [
    "# 方法抽象封装"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11c652f1-98a8-4f9c-99da-d0da91f33cbd",
   "metadata": {},
   "source": [
    "## 方法/函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60eda02b-4181-440d-a662-a22d77b7da23",
   "metadata": {},
   "source": [
    "### 创建函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 551,
   "id": "f076e927-fc4a-463e-8ffc-31dcef79a442",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook1():\n",
    "    print('在吃蛋炒饭')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 552,
   "id": "fe5d2aa4-d3cd-412e-8b75-364742b29d8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在吃蛋炒饭\n"
     ]
    }
   ],
   "source": [
    "cook1()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 553,
   "id": "3078de2a-5db4-4d64-b9d0-859f4e60a357",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在吃蛋炒饭\n"
     ]
    }
   ],
   "source": [
    "cc1 = cook1()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 554,
   "id": "ec0d7a7f-d640-416f-ab42-c0138f6e8e31",
   "metadata": {},
   "outputs": [],
   "source": [
    "cc1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f997120-2845-45df-bebf-ceb4047a1df1",
   "metadata": {},
   "source": [
    "### return返回值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 555,
   "id": "341d05c0-10d7-447f-873b-67ae93786453",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook2():\n",
    "    return '在做蛋炒饭'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 556,
   "id": "daf08c70-d1d7-4c24-a7e2-f3ffd801be73",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = cook2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 557,
   "id": "588c4fd3-63a1-4651-b4a4-0f88a0ab4eca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'在做蛋炒饭'"
      ]
     },
     "execution_count": 557,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 558,
   "id": "205414ba-2799-4510-819b-faf957739ba8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook3():\n",
    "    return 'AFAN', '在做蛋炒饭'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 559,
   "id": "2b784504-3cc5-478c-87c6-866fdba47c0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = cook3()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 560,
   "id": "94afc91c-4d1d-4165-824e-57ffb5d0e503",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('AFAN', '在做蛋炒饭')"
      ]
     },
     "execution_count": 560,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 561,
   "id": "37188959-24d7-4884-91fc-4cf409e84301",
   "metadata": {},
   "outputs": [],
   "source": [
    "res1, res2 = cook3()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 562,
   "id": "d84ed379-16cb-4478-913f-b9a4c9440e6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'AFAN'"
      ]
     },
     "execution_count": 562,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 563,
   "id": "5c1591b6-0131-4e11-a7dc-61bb9d3bd580",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'在做蛋炒饭'"
      ]
     },
     "execution_count": 563,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67cd7004-2677-4124-b75f-196ce44608ff",
   "metadata": {},
   "source": [
    "### 形参和实参"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "128b0142-4adc-49d2-b1e7-62f2877f4199",
   "metadata": {},
   "source": [
    "#### 单参数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ea980c1-bf06-48e0-ad76-22f69ba7b5f1",
   "metadata": {},
   "source": [
    "形式参数——构建联系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 529,
   "id": "db6b3d37-a580-4b32-8fab-21f581634985",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook_food(food):\n",
    "    print(f'在做{food}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e2941cb-d85a-485e-a33e-e2e353c26ceb",
   "metadata": {},
   "source": [
    "实际参数——具体值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 531,
   "id": "c081888e-92d7-4d91-b835-d02f1979dd26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做蛋炒饭\n"
     ]
    }
   ],
   "source": [
    "cook_food('蛋炒饭')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 564,
   "id": "d433a329-6b7a-46fd-8917-bd643ec31ba1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做火锅面\n"
     ]
    }
   ],
   "source": [
    "cook_food('火锅面')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 565,
   "id": "8b5f762d-c35e-4f58-b87d-d6a94d0c61dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做火锅面\n"
     ]
    }
   ],
   "source": [
    "cook_food(food='火锅面')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9dafedb-6351-4be6-a352-e9457fae3195",
   "metadata": {},
   "source": [
    "#### 多参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 566,
   "id": "4f560cca-4868-4b3b-a18c-7333846a58d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook_food1(who, food):\n",
    "    print(f'在做{who}给的{food}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 567,
   "id": "89b254e1-06d0-4fa4-bac6-8cc7d120126f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做居委会给的鸡汤挂面\n"
     ]
    }
   ],
   "source": [
    "cook_food1(who='居委会', food='鸡汤挂面')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 569,
   "id": "2c7964c3-be4b-47a1-ba70-fe50c4abbe10",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做居委会给的鸡汤挂面\n"
     ]
    }
   ],
   "source": [
    "cook_food1('居委会', '鸡汤挂面')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 568,
   "id": "c01cd765-1b90-4d56-8919-542a19200833",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做鸡汤挂面给的居委会\n"
     ]
    }
   ],
   "source": [
    "cook_food1('鸡汤挂面', '居委会')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 528,
   "id": "21196825-4d9a-4d57-8786-466faafe6c0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在做居委会给的鸡汤挂面\n"
     ]
    }
   ],
   "source": [
    "cook_food1(food='鸡汤挂面', who='居委会')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "328b831e-5dcb-42a5-b7e6-f84ae99316df",
   "metadata": {},
   "source": [
    "#### 结合语法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 570,
   "id": "82440758-29d1-4f08-87d2-95697c0ef1b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook_food_channel(who, food):\n",
    "    if who=='居委会':\n",
    "        channel = '派发的'\n",
    "    elif who=='团长':\n",
    "        channel = '团购运输的'\n",
    "    print(f'在吃{who}{channel}{food}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 571,
   "id": "488c1224-5149-4c54-8b90-3ad6108f2616",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在吃居委会派发的鸡汤挂面\n"
     ]
    }
   ],
   "source": [
    "cook_food_channel(who='居委会', food='鸡汤挂面')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 572,
   "id": "b3a947bd-83c0-4c85-8b0f-960f828a63b5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在吃团长团购运输的酱鸭\n"
     ]
    }
   ],
   "source": [
    "cook_food_channel(who='团长', food='酱鸭')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7939c1e1-fbb1-4f9a-906e-f541ca3990a7",
   "metadata": {},
   "source": [
    "#### 默认参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 573,
   "id": "c51139c2-7855-4d61-9eac-478c1c3f092a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "non-default argument follows default argument (Temp/ipykernel_22652/946995653.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/946995653.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    def cook_all(cooker='AFAN', who, food):\u001b[0m\n\u001b[1;37m                                     ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m non-default argument follows default argument\n"
     ]
    }
   ],
   "source": [
    "def cook_all(cooker='AFAN', who, food):\n",
    "    if who=='居委会':\n",
    "        channel = '给的'\n",
    "    elif who=='团长':\n",
    "        channel = '团购运输的'\n",
    "    print(f'{cooker}在做{who}{channel}{food}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 574,
   "id": "85bba10c-b004-4f00-9404-8de562ffa9ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cook_all(who, food, cooker='AFAN'):\n",
    "    if who=='居委会':\n",
    "        channel = '给的'\n",
    "    elif who=='团长':\n",
    "        channel = '团购运输的'\n",
    "    print(f'{cooker}在做{who}{channel}{food}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 575,
   "id": "a880c5a2-c906-4e8b-a7d3-6c8a1a75e120",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AFAN在做团长团购运输的酱鸭\n"
     ]
    }
   ],
   "source": [
    "cook_all('团长', '酱鸭')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 576,
   "id": "a9a99e70-be28-4e7a-95c3-24df61921110",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AFAN在做团长团购运输的酱鸭\n"
     ]
    }
   ],
   "source": [
    "cook_all('团长', '酱鸭', cooker='AFAN')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 577,
   "id": "ba78fc99-a912-418f-8adf-18e742741097",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "KS在做团长团购运输的土豆牛肉\n"
     ]
    }
   ],
   "source": [
    "cook_all('团长', '土豆牛肉', cooker='KS')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dccbcbbb-606d-47d6-8128-d3f72f0df9ee",
   "metadata": {},
   "source": [
    "## 模式方法封装"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 448,
   "id": "090ebd11-e21f-4594-b4c7-4e93da14829b",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA = {'GDP': [14444, 13333, 12222, 10611, 10000, 8888, 7777],\n",
    " '第一产业': [4444, 3333, 2222, 2111, 2000, 1888, 1277],\n",
    " '第二产业': [4000, 4000, 4000, 4500, 4000, 3000, 2750],\n",
    " '第三产业': [6000, 6000, 6000, 4000, 4000, 4000, 3750],\n",
    " '年份': [2022, 2021, 2020, 2019, 2018, 2017, 2016]}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43e4f14e-7105-467b-8593-060608a40743",
   "metadata": {
    "tags": []
   },
   "source": [
    "### 基础模式封装"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64cdcc8f-dfe7-4889-9dda-63b5fe142cac",
   "metadata": {},
   "source": [
    "#### 原先写法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "ff156692-86e4-4c82-92dc-60f2bf6df209",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_2022 = 12222\n",
    "gdp_2021 = 13333"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46a56b2e-7892-4b10-8f37-3ca9e9bde802",
   "metadata": {},
   "source": [
    "A 指标全年xx，比上年增加/减少xx，比上年增长/减少xx.x%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "d6e1eaf7-8b21-4f28-a07a-15e32f3e0291",
   "metadata": {},
   "outputs": [],
   "source": [
    "gdp_2022_increase = gdp_2022 - gdp_2021\n",
    "gdp_2022_rate = gdp_2022_increase / gdp_2021\n",
    "\n",
    "if gdp_2022_increase > 0:\n",
    "    gdp_judge = \"增长\"\n",
    "elif gdp_2022_increase < 0:\n",
    "    gdp_judge = \"下降\"\n",
    "else:\n",
    "    gdp_judge = \"变化\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "5cae0ba2-5233-4c63-b1d7-d21768fd4e59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP全年12222万亿，比上年下降1111万亿，比上年下降8.33%'"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f\"GDP全年{gdp_2022}万亿，比上年{gdp_judge}{abs(gdp_2022_increase)}万亿，\\\n",
    "比上年{gdp_judge}{'%.2f' % (abs(gdp_2022_rate)*100)}%\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01c95cfd-56f7-41c1-801b-99c9916e8bca",
   "metadata": {},
   "source": [
    "#### 抽象封装"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f674d14f-ddc0-48e8-9126-b150c143a9eb",
   "metadata": {},
   "source": [
    "读取数据、变量命名、年份"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "facef4e3-dafd-4e61-a86b-c4e6785ad50f",
   "metadata": {
    "tags": []
   },
   "source": [
    "##### 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 448,
   "id": "d0dae63f-1e91-4d46-a119-83aa5eb1a8b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA = {'GDP': [14444, 13333, 12222, 10611, 10000, 8888, 7777],\n",
    " '第一产业': [4444, 3333, 2222, 2111, 2000, 1888, 1277],\n",
    " '第二产业': [4000, 4000, 4000, 4500, 4000, 3000, 2750],\n",
    " '第三产业': [6000, 6000, 6000, 4000, 4000, 4000, 3750],\n",
    " '年份': [2022, 2021, 2020, 2019, 2018, 2017, 2016]}"
   ]
  },
  {
   "cell_type": "raw",
   "id": "9f124ceb-2026-404c-8f67-6f338db70666",
   "metadata": {},
   "source": [
    "def increase_plain(data, indicator_key):\n",
    "    # 读取数据\n",
    "    indi_list = data[indicator_key]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "758acb89-83ad-41dd-93bd-f3e7cf7adf9e",
   "metadata": {
    "tags": []
   },
   "source": [
    "##### 日期和列表索引"
   ]
  },
  {
   "cell_type": "raw",
   "id": "242ccde6-bfc8-4869-b02d-2755d19f143b",
   "metadata": {},
   "source": [
    "def increase_plain(data, indicator_key, date_key, date=2019):\n",
    "    # 读取数据\n",
    "    indi_list = data[indicator_key]\n",
    "    date_list = data[date_key]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 597,
   "id": "48592290-15c8-4a5f-8ce6-6dce3e95c293",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "for idx, value in enumerate(DATA['年份']):\n",
    "    if value == 2019:\n",
    "        print(idx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 598,
   "id": "c7bba4f0-3540-4909-a872-7dba0ff069c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 598,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA['年份'].index(2019)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "6f74681b-e66c-479b-8b00-b4eef5fba2db",
   "metadata": {},
   "source": [
    "def increase_plain(data, indicator_key, date_key, date=2019):\n",
    "    # 读取数据\n",
    "    indi_list = data[indicator_key]\n",
    "    date_list = data[date_key]\n",
    "    # 确定日期的索引\n",
    "    date_index = date_list.index(date)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9717a6a3-572e-41c4-bfa3-6f9eba74fbca",
   "metadata": {
    "tags": []
   },
   "source": [
    "##### 开始计算"
   ]
  },
  {
   "cell_type": "raw",
   "id": "1666f21d-5cb4-44f2-b13b-1490006fae4c",
   "metadata": {},
   "source": [
    "gdp_2022_increase = gdp_2022 - gdp_2021\n",
    "gdp_2022_rate = gdp_2022_increase / gdp_2021\n",
    "\n",
    "if gdp_2022_increase > 0:\n",
    "    gdp_judge = \"增长\"\n",
    "elif gdp_2022_increase < 0:\n",
    "    gdp_judge = \"下降\"\n",
    "else:\n",
    "    gdp_judge = \"变化\""
   ]
  },
  {
   "cell_type": "raw",
   "id": "97349f82-333d-4685-a32f-b217de1d3bd3",
   "metadata": {},
   "source": [
    "def increase_plain(data, indicator_key, date_key, date=2019):\n",
    "    # 读取数据\n",
    "    indi_list = data[indicator_key]\n",
    "    date_list = data[date_key]\n",
    "    # 确定日期的索引\n",
    "    date_index = date_list.index(date)\n",
    "    # 计算增量增速\n",
    "    indi_now = indi_list[date_index] # 当前指标的数据\n",
    "    indi_inc = indi_now - indi_list[date_index+1] # 增量\n",
    "    indi_rate = indi_inc / indi_list[date_index+1] # 增速\n",
    "    indi_judge = \"\"\n",
    "    if indi_inc > 0:\n",
    "        indi_judge = \"增长\"\n",
    "    elif indi_inc < 0:\n",
    "        indi_judge = \"下降\"\n",
    "    else:\n",
    "        indi_judge = \"变化\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e37c112e-5d0d-4c5c-a540-56b9177a7ec1",
   "metadata": {
    "tags": []
   },
   "source": [
    "##### 开始输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 601,
   "id": "5eb5e0ed-cf91-4daf-891c-863df05a92fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "def increase_plain(data, indicator_key, date_key, date=2019, measure='万亿'):\n",
    "    # 读取数据\n",
    "    indi_list = data[indicator_key]\n",
    "    date_list = data[date_key]\n",
    "    # 确定日期的索引\n",
    "    date_index = date_list.index(date)\n",
    "    # 计算增量增速\n",
    "    indi_now = indi_list[date_index] # 当前指标的数据\n",
    "    indi_inc = indi_now - indi_list[date_index+1] # 增量\n",
    "    indi_rate = indi_inc / indi_list[date_index+1] # 增速\n",
    "    indi_judge = \"\"\n",
    "    if indi_inc > 0:\n",
    "        indi_judge = \"增长\"\n",
    "    elif indi_inc < 0:\n",
    "        indi_judge = \"下降\"\n",
    "    else:\n",
    "        indi_judge = \"变化\"\n",
    "    output_text = f\"{indicator_key}在{date}年为{indi_now}{measure}，\\\n",
    "比上年{indi_judge}{abs(indi_inc)}{measure}，\\\n",
    "比上年{indi_judge}{'%.2f' % (abs(indi_rate)*100)}%\"\n",
    "    return output_text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f7cfaa8-005d-41d6-b750-80ad93857e67",
   "metadata": {},
   "source": [
    "##### 验证结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 602,
   "id": "7ef78863-38ce-4ae0-98f0-6d705a33bbd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP在2022年为14444万亿，比上年增长1111万亿，比上年增长8.33%'"
      ]
     },
     "execution_count": 602,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "increase_plain(DATA\n",
    "              ,indicator_key='GDP'\n",
    "              ,date_key='年份'\n",
    "              ,date=2022\n",
    "              ,measure='万亿')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 603,
   "id": "cca4e1b5-fa37-436f-8cd7-e4772b0892e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GDP在2020年为12222万亿，比上年增长1611万亿，比上年增长15.18%'"
      ]
     },
     "execution_count": 603,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "increase_plain(DATA\n",
    "              ,indicator_key='GDP'\n",
    "              ,date_key='年份'\n",
    "              ,date=2020\n",
    "              ,measure='万亿')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 605,
   "id": "a45437f8-d584-4f2b-9eb7-42f083f4f137",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业在2019年为2111万亿，比上年增长111万亿，比上年增长5.55%'"
      ]
     },
     "execution_count": 605,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "increase_plain(DATA\n",
    "              ,indicator_key='第一产业'\n",
    "              ,date_key='年份'\n",
    "              ,date=2019\n",
    "              ,measure='万亿')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c80e04b9-90c0-4261-997d-83c474463e4d",
   "metadata": {},
   "source": [
    "### 截面模式封装"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd6b230d-d3cb-4a25-a9fe-30b1f62f53b9",
   "metadata": {},
   "source": [
    "#### 原先写法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 616,
   "id": "3a08f2f1-3399-410c-898c-8c6f0d1e7ee7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业占GDP30.77%，第二产业占GDP27.69%，第三产业占GDP41.54%'"
      ]
     },
     "execution_count": 616,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_text = \"\"\n",
    "for key in DATA:\n",
    "    if key in ['GDP', '年份']:\n",
    "        continue\n",
    "    tmp_rate = DATA[key][0] / DATA[\"GDP\"][0] * 100\n",
    "    tmp_text = f\"{key}占GDP{'%.2f' % tmp_rate}%\"\n",
    "    if total_text: # 如果有值\n",
    "        total_text = total_text + \"，\" + tmp_text\n",
    "    else: # 如果没有值\n",
    "        total_text = tmp_text\n",
    "total_text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "523acd12-eed9-46a3-978a-b5beb9caeb54",
   "metadata": {},
   "source": [
    "#### 抽象封装"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 619,
   "id": "0a0132a2-4bfa-4623-81e5-6cdc33fe1c0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cross_plain(data, parent_key, date_key, date=2019):\n",
    "    # 读取数据\n",
    "    parent_list = data[parent_key]\n",
    "    date_list = data[date_key]\n",
    "    # 确定日期的索引\n",
    "    date_index = date_list.index(date)\n",
    "    # 计算占比\n",
    "    output_text = \"\"\n",
    "    for child_key in data:\n",
    "        if child_key in [parent_key, date_key]:\n",
    "            continue\n",
    "        tmp_rate = data[child_key][date_index] / data[parent_key][date_index] * 100\n",
    "        tmp_text = f\"{child_key}占{parent_key}{'%.2f' % tmp_rate}%\"\n",
    "        if output_text: # 如果有值\n",
    "            output_text = output_text + \"，\" + tmp_text\n",
    "        else: # 如果没有值\n",
    "            output_text = f'{date}年，' + tmp_text\n",
    "    return output_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 620,
   "id": "8a4a27c7-d398-4817-86ba-753b0c921973",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2019年，第一产业占GDP19.89%，第二产业占GDP42.41%，第三产业占GDP37.70%'"
      ]
     },
     "execution_count": 620,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross_plain(DATA\n",
    "          ,parent_key='GDP'\n",
    "          ,date_key='年份'\n",
    "          ,date=2019\n",
    "           )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 623,
   "id": "98f858ff-09b1-4335-8bc0-935c9cba8def",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2022年，第一产业占GDP30.77%，第二产业占GDP27.69%，第三产业占GDP41.54%'"
      ]
     },
     "execution_count": 623,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross_plain(DATA\n",
    "          ,parent_key='GDP'\n",
    "          ,date_key='年份'\n",
    "          ,date=2022\n",
    "           )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b6045ad-f1a2-4fb6-bd37-034a921cd0b3",
   "metadata": {},
   "source": [
    "### 模式封装思考"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec85d977-b3c0-474d-a73d-f1dc9876b0fb",
   "metadata": {},
   "source": [
    "#### 是否都封装到位？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fbb07cb-bee9-4130-b027-62b22ce17ec0",
   "metadata": {},
   "source": [
    "日期能否再分？数据传入能否更丰富？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6373fc1-f17a-4430-a5b9-064b389c7473",
   "metadata": {},
   "source": [
    "#### 是否考虑了异常值？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e255c46-a42a-4de4-993a-150ac081729a",
   "metadata": {},
   "source": [
    "如果没有这个值怎么办？如果日期超过了怎么办？分母如果为0怎么办？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "687e1ebd-26d5-4b21-982b-9b04b3a0de28",
   "metadata": {},
   "source": [
    "#### 自己事后能否看懂？别人能否看懂？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acf4141f-c222-419a-9247-2bb1b3f1698c",
   "metadata": {},
   "source": [
    "复杂思考有设计文档吗？你的代码有注释吗？交接的时候怎么办？推广的时候怎么办？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb3671fd-0d09-4ecb-b728-a45c274a12d7",
   "metadata": {},
   "source": [
    "#### 总结：程序设计不易"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15aaa8d6-f7cf-44c4-bc28-43956186f13f",
   "metadata": {},
   "source": [
    "## 类和py文件"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e32ad4e8-d0da-476e-bf8a-2eb5f42d81c1",
   "metadata": {},
   "source": [
    "### 类——方法的汇集"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40097313-9dfe-49c1-a60b-06badff5aa51",
   "metadata": {},
   "source": [
    "#### 类的构建和对象创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 652,
   "id": "3043303d-fa79-4e0c-be64-c86a294e3ef7",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Person:\n",
    "    None"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "255c5df0-8de8-4860-ba7a-7cb0c42ec0f6",
   "metadata": {},
   "source": [
    "类是对象的模板"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 653,
   "id": "29498120-56a8-4cfb-bdbe-94e1a59f36ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "p1 = Person()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 656,
   "id": "b746a2ef-ac89-49cf-b9b7-fc37daa318bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "p2 = Person()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 654,
   "id": "4721bdd0-9088-4cef-8965-28e9a8384627",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<__main__.Person at 0x235f6eb7c10>"
      ]
     },
     "execution_count": 654,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 657,
   "id": "c638ccf9-b152-423d-a431-e7fc867bf4fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<__main__.Person at 0x235f6eb7220>"
      ]
     },
     "execution_count": 657,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 655,
   "id": "4f69945b-b57d-4c7f-91f7-aa8ea0ebc8fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "__main__.Person"
      ]
     },
     "execution_count": 655,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(p1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33fded22-9fe7-4251-84cf-95022f2c05a6",
   "metadata": {},
   "source": [
    "#### init方法和属性"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c91aee7-fcd2-420e-a890-59e3681aa82a",
   "metadata": {},
   "source": [
    "类的方法第一个参数一定是self"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bccfcdba-6ccb-45ea-9859-5f6817d25528",
   "metadata": {},
   "source": [
    "init构造方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 662,
   "id": "eba1806d-f658-4099-8b8c-d5532907636c",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Person:\n",
    "    def __init__(self, name, age):\n",
    "        self.age = age\n",
    "        self.name = name   \n",
    "    def cook(self):\n",
    "        print('做饭')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 663,
   "id": "e8b4b86c-d887-477e-978b-2981ba37c83e",
   "metadata": {},
   "outputs": [],
   "source": [
    "p1 = Person('AFAN', 28)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91fc5216-3d55-4136-85ad-b55cd9f0ed91",
   "metadata": {},
   "source": [
    "类的属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 664,
   "id": "d90bf291-a8a7-4641-82ad-25b2d33ea94e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('AFAN', 28)"
      ]
     },
     "execution_count": 664,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1.name, p1.age"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec3cffba-326d-42b4-8ea6-55f5d39e08bf",
   "metadata": {},
   "source": [
    "类的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 665,
   "id": "58753b65-2e5f-4e8e-b715-b166f72c735b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "做饭\n"
     ]
    }
   ],
   "source": [
    "p1.cook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 666,
   "id": "66793823-4e6d-4cb5-be22-061261e3f0d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "p2 = Person('KS', 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 668,
   "id": "6d27c5d1-33c0-4b38-bd79-419695b0cfd7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('KS', 30)"
      ]
     },
     "execution_count": 668,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p2.name, p2.age"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fcdf98a3-c12a-4ae1-9efd-ea04b927eb81",
   "metadata": {},
   "source": [
    "#### 类的封装"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 669,
   "id": "4acb1c99-c6ee-428c-8678-67f8b4790f84",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Report:\n",
    "    \n",
    "    def increase_plain(self, data, indicator_key, date_key, date=2019, measure='万亿'):\n",
    "        # 读取数据\n",
    "        indi_list = data[indicator_key]\n",
    "        date_list = data[date_key]\n",
    "        # 确定日期的索引\n",
    "        date_index = date_list.index(date)\n",
    "        # 计算增量增速\n",
    "        indi_now = indi_list[date_index] # 当前指标的数据\n",
    "        indi_inc = indi_now - indi_list[date_index+1] # 增量\n",
    "        indi_rate = indi_inc / indi_list[date_index+1] # 增速\n",
    "        indi_judge = \"\"\n",
    "        if indi_inc > 0:\n",
    "            indi_judge = \"增长\"\n",
    "        elif indi_inc < 0:\n",
    "            indi_judge = \"下降\"\n",
    "        else:\n",
    "            indi_judge = \"变化\"\n",
    "        output_text = f\"{indicator_key}在{date}年为{indi_now}{measure}，\\\n",
    "比上年{indi_judge}{abs(indi_inc)}{measure}，\\\n",
    "比上年{indi_judge}{'%.2f' % (abs(indi_rate)*100)}%\"\n",
    "        return output_text\n",
    "    \n",
    "    def cross_plain(self, data, parent_key, date_key, date=2019):\n",
    "        # 读取数据\n",
    "        parent_list = data[parent_key]\n",
    "        date_list = data[date_key]\n",
    "        # 确定日期的索引\n",
    "        date_index = date_list.index(date)\n",
    "        # 计算占比\n",
    "        output_text = \"\"\n",
    "        for child_key in data:\n",
    "            if child_key in [parent_key, date_key]:\n",
    "                continue\n",
    "            tmp_rate = data[child_key][date_index] / data[parent_key][date_index] * 100\n",
    "            tmp_text = f\"{child_key}占{parent_key}{'%.2f' % tmp_rate}%\"\n",
    "            if output_text: # 如果有值\n",
    "                output_text = output_text + \"，\" + tmp_text\n",
    "            else: # 如果没有值\n",
    "                output_text = f'{date}年，' + tmp_text\n",
    "        return output_text   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 670,
   "id": "f256add7-77c7-4578-bc8c-4f30f4d5fd72",
   "metadata": {},
   "outputs": [],
   "source": [
    "report = Report()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 671,
   "id": "3d52cc7d-8219-4d6b-be02-526f0becff19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业在2019年为2111万亿，比上年增长111万亿，比上年增长5.55%'"
      ]
     },
     "execution_count": 671,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "report.increase_plain(DATA\n",
    "              ,indicator_key='第一产业'\n",
    "              ,date_key='年份'\n",
    "              ,date=2019\n",
    "              ,measure='万亿')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 672,
   "id": "bf33006d-f3a2-4916-84d4-edbf8a1d4cb3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2022年，第一产业占GDP30.77%，第二产业占GDP27.69%，第三产业占GDP41.54%'"
      ]
     },
     "execution_count": 672,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "report.cross_plain(DATA\n",
    "          ,parent_key='GDP'\n",
    "          ,date_key='年份'\n",
    "          ,date=2022\n",
    "           )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 673,
   "id": "96d782d1-304c-4b26-aa9e-95f9d2be8e6a",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "increase_plain() missing 1 required positional argument: 'data'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_22652/3491577857.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m Report.increase_plain(DATA\n\u001b[0m\u001b[0;32m      2\u001b[0m               \u001b[1;33m,\u001b[0m\u001b[0mindicator_key\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'第一产业'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m               \u001b[1;33m,\u001b[0m\u001b[0mdate_key\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'年份'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m               \u001b[1;33m,\u001b[0m\u001b[0mdate\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2019\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m               ,measure='万亿')\n",
      "\u001b[1;31mTypeError\u001b[0m: increase_plain() missing 1 required positional argument: 'data'"
     ]
    }
   ],
   "source": [
    "Report.increase_plain(DATA\n",
    "              ,indicator_key='第一产业'\n",
    "              ,date_key='年份'\n",
    "              ,date=2019\n",
    "              ,measure='万亿')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "450855c0-7bf5-4072-bd6f-11e7226ae6a2",
   "metadata": {},
   "source": [
    "### py文件——Python原生的文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 674,
   "id": "3dffbcc5-8bd5-4ada-b0ed-58c459071803",
   "metadata": {},
   "outputs": [],
   "source": [
    "from report import Report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 677,
   "id": "49608335-4380-4257-967e-c90e38941f68",
   "metadata": {},
   "outputs": [],
   "source": [
    "from report import * # 可以导入一批东西"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 675,
   "id": "12b210d4-e546-4c6f-817b-4a498dd73887",
   "metadata": {},
   "outputs": [],
   "source": [
    "r1 = Report()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 678,
   "id": "1ae63fbe-d73a-47fb-b786-af49f966f322",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'GDP': [14444, 13333, 12222, 10611, 10000, 8888, 7777],\n",
       " '第一产业': [4444, 3333, 2222, 2111, 2000, 1888, 1277],\n",
       " '第二产业': [4000, 4000, 4000, 4500, 4000, 3000, 2750],\n",
       " '第三产业': [6000, 6000, 6000, 4000, 4000, 4000, 3750],\n",
       " '年份': [2022, 2021, 2020, 2019, 2018, 2017, 2016]}"
      ]
     },
     "execution_count": 678,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 676,
   "id": "359c86c6-6777-4620-beb4-6ad61aa73162",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'第一产业在2019年为2111万亿，比上年增长111万亿，比上年增长5.55%'"
      ]
     },
     "execution_count": 676,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1.increase_plain(DATA\n",
    "              ,indicator_key='第一产业'\n",
    "              ,date_key='年份'\n",
    "              ,date=2019\n",
    "              ,measure='万亿')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc-autonumbering": true
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
